package com.com.hefei.wdp.example;

import com.com.hefei.wdp.rule.MySelRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
//@EnableDiscoveryClient 用户获取Eureka服务器上注册的服务的基本信息，
//在contorller中注入DiscoveryClient discoveryClient来获取注册的服务信息
@EnableDiscoveryClient
@EnableEurekaClient //eureka客户端
@SpringBootApplication
// ribbon 切换负载均衡策略, name：服务名，configuration：是负载均衡策略类
@RibbonClient(name="PRODUCER",configuration = MySelRule.class)
@EnableCircuitBreaker //Hystrix注解
public class ConsumerRibbonApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerRibbonApplication.class, args);
    }
    @Bean
    @LoadBalanced // 客户端负载均衡机制，默认轮询
    RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }
}
